import User from '@/pages/User/Index'
import Role from '@/pages/Role/Index'
import Menu from '@/pages/Menu/Index'
import LayoutIndex from '@/layout/LayoutIndex'

const components = {
  'sys_user':User,
  'sys_role':Role,
  'sys_menu':Menu,
}

const createRoutes = function (routes) {
  const newRoutes = []
  for (let i=0;i<routes.length;i++) {
    const tempRoute = {}
    tempRoute.name = routes[i].name
    tempRoute.path = routes[i].path
    // console.log(routes[i])
    if(components[routes[i].name] !== undefined){
      tempRoute.component = components[routes[i].name]//Vue.component(routes[i].name,()=>import('../pages/Index/Index.vue'))
    }else {
      tempRoute.component={
        render:c=>c("router-view")
      }
    }
    if(routes[i].children.length>0){
      tempRoute.children = createRoutes(routes[i].children)
    }
    newRoutes.push(tempRoute)
  }
  return newRoutes
}

export {
  LayoutIndex
}

export default createRoutes